/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.model.enums;

import java.util.ArrayList;
import java.util.List;

/**
 * 交易状态信息
 * 
 * @author wy
 * @version $Id: TradeEnum.java, v 0.1 2012-6-1 下午1:24:29 wy Exp $
 */
public enum TradeEnum {

    PAY_WAIT("待付款",false),
    PAY_FAIL("付款失败",true),
    PAY_CANCEL("取消付款",true),
    PAY_IN_HAND("付款正在处理",false),
    PAY_SUCCESS("付款成功",true),
    REFUND_PAY_ACCEPT("系统已受理",false),
    REFUND_TERMINAL_ACCEPT("终端已受理",false),
    REFUND_CANCEL("取消退款",true),
    REFUND_FAIL("退款失败",true),
    REFUND_SUCCESS("退款成功",true);

    private String  msg;
    private Boolean isLast;

    /**
     * @param msg 该状态的信息
     * @param isLast 是否是完结状态
     */
    TradeEnum(String msg, Boolean isLast) {
        this.msg = msg;
        this.isLast = isLast;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Boolean getIsLast() {
        return isLast;
    }

    public void setIsLast(Boolean isLast) {
        this.isLast = isLast;
    }

    /**
     * 根据交易状态获取enum
     * 
     * @param tradeStatus
     * @return
     */
    public static TradeEnum getTradeEnum(String tradeStatus) {
        for (TradeEnum te : TradeEnum.values()) {
            if (te.name().equalsIgnoreCase(tradeStatus)) {
                return te;
            }
        }
        return null;
    }

    /**
     * 根据是否终结来获得msgs
     * 
     * @param end
     * @return
     */
    public static List<String> getByIsLast(boolean end) {
        List<String> msgs = new ArrayList<String>();
        for (TradeEnum te : TradeEnum.values()) {
            if (te.getIsLast() == end) {
                msgs.add(te.getMsg());
            }
        }
        return msgs;
    }
    /**
     * 根据是否终结来获得msgs
     * 
     * @param end
     * @return
     */
    public static List<String> getValuesByIsLast(boolean end) {
        List<String> msgs = new ArrayList<String>();
        for (TradeEnum te : TradeEnum.values()) {
            if (te.getIsLast() == end) {
                msgs.add(te.name());
            }
        }
        return msgs;
    }
    
}
